﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DevComponents.DotNetBar.SuperGrid;

namespace SyncConfig
{
    public static class SuperGridControlExtention
    {
        public static DataRow GetCurrentRow(this SuperGridControl c)
        {
            if (c.PrimaryGrid.ActiveRow != null)
            {
                DataRowView rowView = ((GridRow)c.PrimaryGrid.Rows[c.PrimaryGrid.ActiveRow.Index]).DataItem as DataRowView;
                if (rowView != null)
                    return rowView.Row;
            }
            return null;
        }

        public static T GetCurrentRow<T>(this SuperGridControl c) where T:DataRow
        {
            if (c.PrimaryGrid.ActiveRow != null)
            {
                DataRowView rowView = ((GridRow)c.PrimaryGrid.Rows[c.PrimaryGrid.ActiveRow.Index]).DataItem as DataRowView;
                if (rowView != null)
                    return rowView.Row as T ;
            }
            return null;
        }

        public static DataRow GetDataRow(this SuperGridControl c, int index)
        {

            DataRowView rowView = ((GridRow)c.PrimaryGrid.Rows[index]).DataItem as DataRowView;
            if (rowView != null)
                return rowView.Row;
            return null;
        }
        public static T GetDataRow<T>(this SuperGridControl c, int index) where T:DataRow
        {

            DataRowView rowView = ((GridRow)c.PrimaryGrid.Rows[index]).DataItem as DataRowView;
            if (rowView != null)
                return rowView.Row as T;
            return null;
        }

    }
}
